//
//@File    :	15.7_error1.cpp
//@Time    :	2022/03/10 11:02:41
//@Auther  :	Sun Sheng
//@Contact :	970340843@qq.com
//@Desc    :	using the abort() function
//

//abort()位于头文件<cstdlib>中,
//是向标准错误流(即cerr使用的错误流)发送消息abnormal program termination(程序异常终止)
//然后终止程序,还返回一个随实现而异的值,告诉父进程(或操作系统)处理失败

//abort()是否刷新文件缓冲区取决于实现
//exit()刷新文件缓冲区但不显示消息


// 计算调和平均数
#include <iostream>
#include <cstdlib>

double hmean(double a,double b);

int main()
{
    double x,y,z;

    std::cout<<"Enter two numbers: ";
    while (std::cin>>x>>y)
    {
        z = hmean(x,y);
        std::cout<<"Harmonice mean od "<<x<<" and "<<y<<"is"<<z<<std::endl;
        std::cout<<"Enter next set of numbers<q to quit>: ";
    }
    std::cout<<"Bye!\n";
    system("pause");
    return 0;
}

double hmean(double a,double b){
    if (a==-b)
    {
        std::cout<<"untenable arguments to hmean()\n";
        std::abort();
    }
    return 2.0*a*b/(a+b);
}